package com.itheima.afternoon.demo05;

import java.util.concurrent.Semaphore;

public class MySemaphore implements Runnable {
    private Semaphore semaphore = new Semaphore(2);

    @Override
    public void run() {
        try {
            semaphore.acquire();
            System.out.println("获得了行驶权，开始行驶");
            Thread.sleep(1000);
            System.out.println("归还行驶权");
            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
